package com.warmlight.voicepacket.utils;

import com.warmlight.voicepacket.http.Callback;
import com.warmlight.voicepacket.http.HttpClient;
import com.warmlight.voicepacket.http.HttpConfig;

import java.io.IOException;
import java.util.List;
import java.util.TreeMap;

import okhttp3.Call;

public class ShareCollectCallBackUtils {

    /**
     *
     * @param id
     * @param type 1 yuyin 2 bodan
     */
    public static void shareCallBack(String id,String type){

        TreeMap<String,String> map = new TreeMap<>();
        map.put("audio_id",id);
        map.put("type",type);
        HttpClient.post(HttpConfig.SERVER + HttpConfig.SHARE, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, String response) {
//                String string = response.body().string();
//                ArrayList<Map<String, String>> listMapByJson = JSONUtils.getListMapByJson(string);
//                if (listMapByJson.size()>0){
//                    Map<String, String> map1 = listMapByJson.get(0);
//                    if ("200".equals(map1.get("code"))){
//                    }
//                }
            }
        });

    }

    /**
     *
     * @param id
     * @param type 1 shouc -1 cancle
     */
    public static void collectCallBack(String id,String type,String coverId){

        TreeMap<String,String> map = new TreeMap<>();
        map.put("audio_id",id);
        map.put("type",type);
        map.put("member_cover_id",coverId);
        HttpClient.post(HttpConfig.SERVER + HttpConfig.collect, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, String response) {
//                String string = response.body().string();
//                ArrayList<Map<String, String>> listMapByJson = JSONUtils.getListMapByJson(string);
//                if (listMapByJson.size()>0){
//                    Map<String, String> map1 = listMapByJson.get(0);
//                    if ("200".equals(map1.get("code"))){
//                    }
//                }
            }
        });

    }
    /**
     *
     * @param id
     * @param type 1 shouc -1 cancle
     */
    public static void collectCallBack(List<String> id, String type,String coverId){

        StringBuffer buffer = new StringBuffer();
        for (String s :id){
            buffer.append(s);
            buffer.append(",");
        }

        String ids = "";
        if (buffer.length()>0){
            ids = buffer.substring(0, buffer.length() - 1);
        }

        TreeMap<String,String> map = new TreeMap<>();
        map.put("audio_id",ids);
        map.put("type",type);
        HttpClient.post(HttpConfig.SERVER + HttpConfig.collect, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, String response) {
//                String string = response.body().string();
//                ArrayList<Map<String, String>> listMapByJson = JSONUtils.getListMapByJson(string);
//                if (listMapByJson.size()>0){
//                    Map<String, String> map1 = listMapByJson.get(0);
//                    if ("200".equals(map1.get("code"))){
//                    }
//                }
            }
        });

    }
}
